<script>
$(function() {
  /* scroll plugin */
  $.scrollUp({scrollText: ''});

  /* beautify select */
  $('.selectpicker').selectpicker({width:'auto', style:'btn-default'});

  /* alerts */
  $('.alert').alert();

  /* masonry display */
  var $container = $('#adv-results');

  $container.infinitescroll({
    navSelector: '#page-nav',
    nextSelector: '#page-nav a',
    itemSelector: 'div .msry-item',
    speed: 'normal',
    loading: {
      finishedMsg: '<em>No more pages to load.</em>',
      img: 'http://i.imgur.com/6RMhx.gif'
    }
  },
  function(items) {
    var $items = $(items).css({opacity:0});
    $items.imagesLoaded(function() {
      $items.animate({opacity:1});
      $items.find('a').tooltip({placement:'right', html:true});
      $container.masonry('appended', $items, true);
    });
  });

  var $items = $container.find('.msry-item');
  $container.empty();
  $container.masonry({
    itemSelector: '.msry-item',
    columnWidth: 150,
    gutter: 10,
  });

  $items.imagesLoaded().progress(function(load, image) {
    var $msry_item = $(image.img).parents('.msry-item');
    $msry_item.appendTo($container);
    $msry_item.find('a').tooltip({placement:'right', html:true});
    $container.masonry('appended', $msry_item);
  });
});
</script>
